<?php
class IXCommon
{
    public static function get_url($url,$refer='')
    {
        //启动一个CURL会话
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_REFERER, $refer);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

        // 执行操作
        $result = curl_exec($ch);
        $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);

        // 关闭CURL会话
        curl_close($ch);
        return array('code'=>$httpcode,'content'=>$result);
    }
    
    /**
     * 得到用户的IP
     */
    public static function getUserHostAddress()
    {
        switch(true)
        {
            case ($ip=getenv("HTTP_X_FORWARDED_FOR")):
                break;
            case ($ip=getenv("HTTP_CLIENT_IP")):
                break;
            default:
                $ip=getenv("REMOTE_ADDR") ? getenv("REMOTE_ADDR") : '127.0.0.1';
        }
        if (strpos($ip, ', ') > 0)
        {
            $ips = explode(', ', $ip);
            $ip = $ips[0];
        }
        return $ip;
    }

    public static function hash_pwd($pwd)
    {
        return md5(md5($pwd.'daU#sDGK$'));
    }
}